﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;
namespace QuanLyThi
{
    public partial class FrmLichThi : Form
    {
        public static string mConnect = FrmMain.mConnect;
        private string msql = "";
        public DGC_Library mLibrary = new DGC_Library(mConnect);

        public FrmLichThi()
        {
            InitializeComponent();
            this.Load();           
        }
        private void button6_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void Load()
        {
            ctungay.Value = DateTime.Now;
            cdenngay.Value = DateTime.Now;
            msql = "Select * from tb_CTdaotao order by CT_daotao";
            DataTable dt = mLibrary.GetDataTable(msql, "table");
            cchuongtrinhdt.DataSource = dt;
            cchuongtrinhdt.DisplayMember = "ct_daotao";
            cchuongtrinhdt.ValueMember = "MS_daotao";        
           
        }

        private void cchuongtrinhdt_SelectionChangeCommitted(object sender, EventArgs e)
        {
            msql = "Select a.* from tb_Khoadaotao a " +
                  " inner join tb_cauhinhCtdaotao b " +
                  " on a.MS_Khoadaotao=b.ms_Khoadaotao " +
                  " Where b.ms_daotao="+cchuongtrinhdt.SelectedValue.ToString();
            DataTable dt1 = mLibrary.GetDataTable(msql, "table");
            ckhoa.DataSource = dt1;
            ckhoa.DisplayMember = "khoadaotao";
            ckhoa.ValueMember = "MS_khoadaotao";
        }  
   
    
        private void button6_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

      

        private void ckhoa_SelectionChangeCommitted(object sender, EventArgs e)
        {
            try
            {
                string tungay = ctungay.Value.ToString("dd/MM/yyyy");
                string denngay = cdenngay.Value.ToString("dd/MM/yyyy");
                string khoa=ckhoa.SelectedValue.ToString();
                msql = "Select c.MS_lop, c.Tenlop, b.mondaotao, f.ms_hssv, f.hovaten, g.tenloaithi, e.ngaythi, e.giothi "+
                      "  from tb_cauhinhlop a inner join tb_mondaotao b on a.ms_mondaotao=b.ms_mondaotao inner join tb_lopdaotao c "+
                      "  on a.ms_lop=c.ms_lop inner join tb_khoadaotao d on c.ms_khoadaotao=d.ms_khoadaotao inner join tb_hssvthi e "+
                      "  on e.ms_mondaotao=a.ms_mondaotao and a.ms_lop=e.ms_lop inner join tb_hssv f on e.ms_hssv=f.ms_hssv "+
                      "  inner join tb_loaihinhthi g on e.ms_loaithi=g.ms_loaithi Where e.ketqua is null and d.ms_khoadaotao="+khoa+ 
                      "  and e.ngaythi>=convert(datetime,'"+tungay+"',103) and e.ngaythi<=convert(datetime,'"+denngay+"',103)"+
                      "  order by c.MS_lop,b.mondaotao,f.ms_hssv";
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.DataSource = mLibrary.GetDataTable(msql, "a");
            }
            catch (Exception)
            {
                MessageBox.Show("Bạn hãy chọn Chương trình,Khoa trước khi chọn ngày", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void ctungay_ValueChanged(object sender, EventArgs e)
        {
            ckhoa_SelectionChangeCommitted(null, null);
        }

        private void cdenngay_ValueChanged(object sender, EventArgs e)
        {
            ckhoa_SelectionChangeCommitted(null, null);
        }

       


      

      

         
     
    }
}
